package com.example.network.parse.xml

import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer

/**
 * 模拟服务器返回数据
 */
class XmlMocker(path: String) {

    private var server: MockWebServer = MockWebServer()
    var baseUrl: String = ""

    init {
        server.start()
        val response = MockResponse()
            .setResponseCode(200)
            .setBody(
                """
                <apps>
                    <app>
                        <id>1</id>
                        <name>Google Maps</name>
                        <version>1.0</version>
                    </app>
                    <app>
                        <id>2</id>
                        <name>Chrome</name>
                        <version>2.1</version>
                    </app>
                    <app>
                        <id>3</id>
                        <name>Google Play</name>
                        <version>2.3</version>
                    </app>
                </apps>
                 """
            )
        server.enqueue(response)
        baseUrl = server.url(path).toString()
    }
}